package bcontrollers

import (
	// "fmt"
	// "encoding/json"

	"advertoper/banner_manage/bservice"
	"advertoper/controllers"
	"advertoper/errorcode"
)

type BannerUserController struct {
	controllers.URLSignController
}

//获取有效的banner信息
// @router /get-data [get]
func (p *BannerUserController) GetUserBannerData() {
	defer p.Output("GetUserBannerData")
	p.ForceHTTPS()

	//根据ServerCode获得ids和layout
	serverCode := p.GetString("server_code", "all")
	_, _, data := bservice.GetBannerControllerService().ControllerList(serverCode)
	if len(data) == 0 {
		p.Resp["code"] = 101
		p.Resp["msg"] = "无效的serverCode"
	}
	req := &bservice.BannerDataUserListReq{}
	req.Ids = data[0].ItemOrder
	req.RegionCode = p.GetString("region_code", "all")
	req.ServerCode = serverCode
	req.Channel = p.GetString("channel", "all")
	req.VersionCode, _ = p.GetInt("version_code", 0)

	appkey := p.GetString("appkey", "")
	plat := "android"
	if appkey == "cc0dec8c07444e9dadb75d41218c4fe4" {
		plat = "ios"
	}
	req.Plat = plat

	bannerItem := bservice.GetBannerManageService().UserGetBannerList(req)
	p.Resp["code"] = errorcode.EC_GL_SUCCESS
	p.Resp["msg"] = errorcode.Msg(errorcode.EC_GL_SUCCESS)
	p.Resp["layout"] = data[0].Layout
	p.Resp["item"] = bannerItem
}
